package cn.ricecode.restructure.design.chain;

public abstract class AbstractLogger {


    protected int level;

    private AbstractLogger nextLogger;

    //关键点：设置下一个Logger
    public void setNextLogger(AbstractLogger abstractLogger) {
        this.nextLogger = abstractLogger;
    }

    public void loadMessage(Integer level) {

        //只有日志级别符合要求才输出
        if(this.level<=level){
            write();
        }

        //关键点：如果下一个不为空，就调用下一个
        if (this.nextLogger != null) {
            this.nextLogger.loadMessage(level);
        }
    }

    abstract protected void write();
}
